package com.oa.srms.apps.business.student.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.oa.srms.apps.business.dormitory.IBedInfoService;
import com.oa.srms.apps.business.student.IFamilyInfoService;
import com.oa.srms.apps.business.student.IMajorInfoService;
import com.oa.srms.apps.business.student.IScoreInfoService;
import com.oa.srms.apps.business.student.IStudentDetailService;
import com.oa.srms.apps.dao.student.IStudentDetailDao;
import com.oa.srms.apps.entity.student.StudentDetailValue;

public class StudentDetailServiceImpl implements IStudentDetailService {
	@Autowired
	private IMajorInfoService majorInfoService;
	@Autowired
	private IFamilyInfoService familyInfoService;
	@Autowired
	private IScoreInfoService scoreInfoService;
	@Autowired
	private IBedInfoService bedInfoService;
	@Autowired
	private StudentDetailValue studentDetailValue;
	@Autowired
	private IStudentDetailDao studentDetailDao;

	@Override
	public Integer addStudentDetail(String gender, String idCard, String hometown,
			String politician, Integer majorId, Integer grade,
			String telphone, Integer familyInfoId, String cardId,
			Integer scoreInfoId) throws Exception {
		studentDetailValue.setGender(gender);
		studentDetailValue.setIdCard(idCard);
		studentDetailValue.setHometown(hometown);
		studentDetailValue.setPolitician(politician);
		studentDetailValue.setMajorInfo(majorInfoService.queryByMajorId(majorId));
		studentDetailValue.setGrade(grade);
		studentDetailValue.setTelphone(telphone);
		studentDetailValue.setFamilyInfo(familyInfoService.queryById(familyInfoId));
		studentDetailValue.setCardId(cardId);
		studentDetailValue.setScoreInfo(scoreInfoService.queryById(scoreInfoId));
		return studentDetailDao.addStudentDetail(studentDetailValue);
	}

	@Override
	public void modifyStudentDetail(Integer id, String gender, String idCard,
			String hometown, String politician, Integer majorId, Integer grade,
			Integer classNo, String telphone, Integer bedInfoId,
			String cardId) throws Exception {
		studentDetailValue = this.queryById(id);
		if (studentDetailValue != null) {
			studentDetailValue.setGender(gender);
			studentDetailValue.setIdCard(idCard);
			studentDetailValue.setHometown(hometown);
			studentDetailValue.setPolitician(politician);
			studentDetailValue.setMajorInfo(majorInfoService.queryByMajorId(majorId));
			studentDetailValue.setGrade(grade);
			studentDetailValue.setClassNo(classNo);
			studentDetailValue.setTelphone(telphone);
			if(bedInfoId != null && bedInfoId != -1)
			studentDetailValue.setBedInfo(bedInfoService.queryById(bedInfoId));
			studentDetailValue.setCardId(cardId);
			studentDetailDao.editStudentDetail(studentDetailValue);
		}

	}

	@Override
	public void modifyStudentDetail(Integer id, String politician,
			String telphone) throws Exception {
		studentDetailValue = this.queryById(id);
		if (studentDetailValue != null) {
			studentDetailValue.setPolitician(politician);
			studentDetailValue.setTelphone(telphone);
			studentDetailDao.editStudentDetail(studentDetailValue);
		}
		
	}

	@Override
	public void modifyStudentDetail(Integer id, Integer classNo, String telphone, Integer bedInfoId) throws Exception {
		studentDetailValue = this.queryById(id);
		if (studentDetailValue != null) {
			studentDetailValue.setClassNo(classNo);
			studentDetailValue.setTelphone(telphone);
			if(bedInfoId != null && bedInfoId != -1)
			studentDetailValue.setBedInfo(bedInfoService.queryById(bedInfoId));
			studentDetailDao.editStudentDetail(studentDetailValue);
		}
		
	}
	
	@Override
	public StudentDetailValue queryById(Integer id) throws Exception {
		return studentDetailDao.queryById(id);
	}

	@Override
	public void modifyStudentDetail(Integer id, Integer classNo)
			throws Exception {
		studentDetailValue = this.queryById(id);
		if (studentDetailValue != null) {
			studentDetailValue.setClassNo(classNo);
			studentDetailDao.editStudentDetail(studentDetailValue);
		}
		
	}

}
